home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Microsoft Plateform / Visual Basic 5.0 / Msvb50.ace / msvb50 / MSVB50 / VB / SETUPKIT / SETUP1 / LOGGING.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-10-25  |  11.5 KB  |  295 lines

  1. Attribute VB_Name = "basLogging"
  2. Option Explicit
  3. Option Compare Text
  4.  
  5. '
  6. ' Module basLogging (32-bit functionality only)
  7. '
  8. 'The routines in this module are used for logging actions,
  9. 'warnings, notes and errors in an application removal
  10. 'logfile.  This logfile will be used by the application
  11. 'removal utility (ST5UNST.EXE) in the event that the user
  12. 'decides to remove the installed application (via a Program
  13. 'Manager icon under Windows NT or the Add/Remove Programs
  14. 'control panel applet under Windows 95).
  15. '
  16. 'The functions are based on transaction-like "actions".
  17. 'Whenever the setup program starts to process a new action
  18. '(an action is anything which the application removal
  19. 'utility must undo), the function NewAction() must be
  20. 'called with the appropriate parameters for that action
  21. '(search for NewAction in this project to see how the
  22. 'correct parameters for various actions are formed).
  23. 'When the action has been successfully completed, the
  24. 'function CommitAction() is called, or, if the
  25. 'action was not successfully completed, AbortAction()
  26. 'must be called.  If CommitAction() is called, then the
  27. 'action is logged at that point, and the application
  28. 'removal utility will undo that action (example, delete
  29. 'a file which was copied by setup).
  30. '
  31. 'Actions may be nested (for instance, a file copy
  32. 'action may have a nested direction creation action).
  33. 'Any errors, warnings or notes logged will note in
  34. 'the logfile the pending action (if any).  Even if
  35. 'an error is logged, the pending action must either
  36. 'be committed or canceled.  See comments for each
  37. 'function below for more specifics.
  38. '
  39.  
  40. 'Application removal is only supported for 32-bit projects
  41.  
  42. 'Set this constant to FALSE if you do not want warnings to appear
  43. 'in the logfile
  44. Global Const fLOG_WARNINGS = True
  45.  
  46. 'Global Action Key constants
  47. Global Const gstrKEY_PRIVATEFILE = "PrivateFile"
  48. Global Const gstrKEY_TEMPFILE = "TempFile"
  49. Global Const gstrKEY_SHAREDFILE = "SharedFile"
  50. Global Const gstrKEY_SYSTEMFILE = "SystemFile"
  51. Global Const gstrKEY_CREATEDIR = "CreateDir"
  52. Global Const gstrKEY_PROGMANGROUP = "ProgManGroup"
  53. Global Const gstrKEY_PROGMANITEM = "ProgManItem"
  54. Global Const gstrKEY_SHELLFOLDER = "ShellFolder"
  55. Global Const gstrKEY_SHELLLINK = "ShellLink"
  56. Global Const gstrKEY_DLLSELFREGISTER = "DllSelfRegister"
  57. Global Const gstrKEY_EXESELFREGISTER = "ExeSelfRegister"
  58. Public Const gstrKEY_TLBREGISTER = "TLBRegister"
  59. Global Const gstrKEY_REMOTEREGISTER = "RemoteRegister"
  60. Global Const gstrKEY_REGKEY = "RegKey"
  61. Global Const gstrKEY_REGVALUE = "RegValue"
  62.  
  63. 'VB5STKIT.DLL logging errors
  64. Private Const LOGERR_SUCCESS = 0
  65. Private Const LOGERR_INVALIDARGS = 1
  66. Private Const LOGERR_OUTOFMEMORY = 2
  67. Private Const LOGERR_EXCEEDEDCAPACITY = 3
  68. Private Const LOGERR_WRITEERROR = 4
  69. Private Const LOGERR_NOCURRENTACTION = 5
  70. Private Const LOGERR_UNEXPECTED = 6
  71. Private Const LOGERR_FILENOTFOUND = 7
  72.  
  73. 'Logging error Severities
  74. Private Const LogErrOK = 1 ' OK to continue upon this error
  75. Private Const LogErrFatal = 2 ' Must terminate install upon this error
  76.  
  77. 'SKIT432.DLL interfaces
  78. Private Declare Function DllAbortAction Lib "VB5STKIT.DLL" Alias "AbortAction" () As Long
  79. Private Declare Function DllAddActionNote Lib "VB5STKIT.DLL" Alias "AddActionNote" (ByVal lpszNote As String) As Long
  80. Private Declare Function DllChangeActionKey Lib "VB5STKIT.DLL" Alias "ChangeActionKey" (ByVal lpszNewKey As String) As Long
  81. Private Declare Function DllCommitAction Lib "VB5STKIT.DLL" Alias "CommitAction" () As Long
  82. Private Declare Function fDllWithinAction Lib "VB5STKIT.DLL" Alias "fWithinAction" () As Long
  83. Private Declare Function DllLogError Lib "VB5STKIT.DLL" Alias "LogError" (ByVal lpszERROR As String, ByVal lpszDURINGACTION As String, ByVal lpszErrMsg As String) As Long
  84. Private Declare Function DllLogNote Lib "VB5STKIT.DLL" Alias "LogNote" (ByVal lpszNote As String) As Long
  85. Private Declare Function DllLogWarning Lib "VB5STKIT.DLL" Alias "LogWarning" (ByVal lpszWARNING As String, ByVal lpszDURINGACTION As String, ByVal lpszWarningMsg As String) As Long
  86. Private Declare Function DllNewAction Lib "VB5STKIT.DLL" Alias "NewAction" (ByVal lpszKey As String, ByVal lpszData As String) As Long
  87. Private Declare Function DllEnableLogging Lib "VB5STKIT.DLL" Alias "EnableLogging" (ByVal lpszFilename As String) As Long
  88. Private Declare Function DllDisableLogging Lib "VB5STKIT.DLL" Alias "DisableLogging" () As Long
  89.  
  90. '-----------------------------------------------------------
  91. ' SUB: AbortAction
  92. '
  93. ' Aborts the current action.
  94. '-----------------------------------------------------------
  95. '
  96. Sub AbortAction()
  97.     ShowLoggingError DllAbortAction(), LogErrFatal
  98. End Sub
  99.  
  100. '-----------------------------------------------------------
  101. ' SUB: AddActionNote
  102. '
  103. ' Adds an note which will be written to the log file
  104. ' immediately following the current action
  105. '-----------------------------------------------------------
  106. '
  107. Sub AddActionNote(ByVal strNote As String)
  108.     ShowLoggingError DllAddActionNote(strNote), LogErrOK
  109. End Sub
  110.  
  111. '-----------------------------------------------------------
  112. ' SUB: ChangeActionKey
  113. '
  114. ' Changes the key of the current action.
  115. '-----------------------------------------------------------
  116. '
  117. Sub ChangeActionKey(ByVal strNewKey As String)
  118.     ShowLoggingError DllChangeActionKey(strNewKey), LogErrFatal
  119. End Sub
  120.  
  121. '-----------------------------------------------------------
  122. ' SUB: CommitAction
  123. '
  124. ' Marks the successful completion of the current action.
  125. ' The action will be output to the log file.
  126. '-----------------------------------------------------------
  127. '
  128. Sub CommitAction()
  129.     ShowLoggingError DllCommitAction(), LogErrFatal
  130. End Sub
  131.  
  132. '-----------------------------------------------------------
  133. ' SUB: DisableLogging
  134. '
  135. ' Disables application removal logging.  All logging
  136. ' functions can still be called, and must still be
  137. ' symentically correct, but no data will be written to disk.
  138. '-----------------------------------------------------------
  139. '
  140. Sub DisableLogging()
  141.     ShowLoggingError DllDisableLogging(), LogErrFatal
  142. End Sub
  143.  
  144. '-----------------------------------------------------------
  145. ' SUB: EnableLogging
  146. '
  147. ' Enables application setup/removal logging to the specified logfile
  148. '-----------------------------------------------------------
  149. '
  150. Sub EnableLogging(ByVal strLogFileName As String)
  151.     ShowLoggingError DllEnableLogging(strLogFileName), LogErrFatal
  152. End Sub
  153.  
  154. '-----------------------------------------------------------
  155. ' SUB: LogError
  156. '
  157. ' Logs an error to the logfile.  The action is NOT aborted.
  158. '-----------------------------------------------------------
  159. '
  160. Sub LogError(ByVal strErr As String)
  161.     ShowLoggingError DllLogError(ResolveResString(resLOG_ERROR), ResolveResString(resLOG_DURINGACTION), strErr), LogErrFatal
  162. End Sub
  163.  
  164. '-----------------------------------------------------------
  165. ' SUB: LogWarning
  166. '
  167. ' Logs a warning to the logfile.  The action is NOT aborted.
  168. ' Warnings are different from errors in that generally
  169. ' warnings are not brought to the end user's attention.
  170. ' Also, the bootstrapper does not ever log warnings.  It only
  171. ' logs errors.
  172. '
  173. ' The logging of warnings can be turned off by changing the
  174. ' value of fLOG_WARNINGS in the declarations section of this
  175. ' module.
  176. '-----------------------------------------------------------
  177. '
  178. Sub LogWarning(ByVal strWarning As String)
  179.     If fLOG_WARNINGS Then
  180.         ShowLoggingError DllLogWarning(ResolveResString(resLOG_WARNING), ResolveResString(resLOG_DURINGACTION), strWarning), LogErrFatal
  181.     End If
  182. End Sub
  183.  
  184. '-----------------------------------------------------------
  185. ' SUB: LogNote
  186. '
  187. ' Logs a note to the logfile.  It is not necessary to have
  188. ' a current action in order to execute this subroutine.
  189. '-----------------------------------------------------------
  190. '
  191. Sub LogNote(ByVal strNote As String)
  192.     ShowLoggingError DllLogNote(strNote), LogErrOK
  193. End Sub
  194.  
  195. '-----------------------------------------------------------
  196. ' SUB: NewAction
  197. '
  198. ' Marks the start of a new action for logging.  If this
  199. ' routine is called before any current action is committed
  200. ' or aborted, the previous action will be placed
  201. ' on a stack.  Once the new action has been committed or
  202. ' aborted, the previous action will become active again.
  203. ' The reporting of errors, warnings, notes and action
  204. ' results are not printed until the action aborts or
  205. ' commits.
  206. ' Several actions may be stacked in a first-in-first-out
  207. ' manner by calling this routine repeatedly.
  208. '-----------------------------------------------------------
  209. '
  210. Sub NewAction(ByVal strKey As String, ByVal strData As String)
  211.     ShowLoggingError DllNewAction(strKey, strData), LogErrFatal
  212. End Sub
  213.  
  214. Sub ShowLoggingError(ByVal lErr As Long, ByVal lErrSeverity As Long)
  215.     If lErr = LOGERR_SUCCESS Then
  216.         Exit Sub
  217.     End If
  218.     
  219.     Dim strErrMsg As String
  220.     Static fRecursive As Boolean
  221.     
  222.     If fRecursive Then
  223.         'If we're getting called recursively, we're likely
  224.         'getting errors while trying to write out errors to
  225.         'the logfile.  Nothing to do but turn off logging
  226.         'and abort setup.
  227.         DisableLogging
  228.         MsgError ResolveResString(resUNEXPECTED), vbExclamation Or vbOKOnly, gstrTitle
  229.         ExitSetup frmSetup1, gintRET_FATAL
  230.     End If
  231.  
  232.     fRecursive = True
  233.  
  234.     Select Case lErr
  235.         Case LOGERR_OUTOFMEMORY, LOGERR_WRITEERROR, LOGERR_UNEXPECTED, LOGERR_FILENOTFOUND
  236.             strErrMsg = ResolveResString(resUNEXPECTED)
  237.         
  238.         Case LOGERR_INVALIDARGS, LOGERR_EXCEEDEDCAPACITY, LOGERR_NOCURRENTACTION
  239.             'Note: These errors are most likely the result of improper customization
  240.             'of this project.  Make certain that any changes you have made to these
  241.             'files are valid and bug-free.
  242.             'LOGERR_INVALIDARGS -- some parameter to a logging function was invalid or improper
  243.             'LOGERR_EXCEEDEDCAPACITY -- the stacking depth of actions has probably been
  244.             '   exceeded.  This most likely means that CommitAction or AbortAction statements
  245.             '   are missing from your code.
  246.             'LOGERR_NOCURRENTACTION -- the logging function you tried to use requires that
  247.             '   there be a current action, but there was none.  Check for a missing NewAction
  248.             '   statement.
  249.             strErrMsg = ResolveResString(resUNEXPECTED)
  250.         Case Else
  251.             strErrMsg = ResolveResString(resUNEXPECTED)
  252.         'End Case
  253.     End Select
  254.     
  255.     Dim iRet As Integer
  256.     Dim fAbort As Boolean
  257.     
  258.     fAbort = False
  259.     If lErrSeverity = LogErrOK Then
  260.         ' User can select whether or not to continue
  261.         iRet = MsgFunc(strErrMsg, MB_OKCANCEL Or MB_ICONEXCLAMATION, gstrTitle)
  262.         If gfNoUserInput Then iRet = IDCANCEL ' can't continue if silent install.
  263.         Select Case iRet
  264.             Case IDOK
  265.             Case IDCANCEL
  266.                 fAbort = True
  267.             Case Else
  268.                 fAbort = True
  269.             'End Case
  270.         End Select
  271.     Else
  272.         ' Fatal
  273.         MsgFunc strErrMsg, MB_OK Or MB_ICONEXCLAMATION, gstrTitle
  274.         fAbort = True
  275.     End If
  276.  
  277.     If fAbort Then
  278.         ExitSetup frmCopy, gintRET_ABORT
  279.     End If
  280.  
  281.     fRecursive = False
  282.  
  283. End Sub
  284.  
  285. '-----------------------------------------------------------
  286. ' FUNCTION: fWithinAction
  287. '
  288. ' Returns TRUE iff there is a current Action
  289. '-----------------------------------------------------------
  290. '
  291. Function fWithinAction() As Boolean
  292.     fWithinAction = fDllWithinAction()
  293. End Function
  294.  
  295.